package com.example.firstproject.service;

import com.example.firstproject.entity.User;
import com.example.firstproject.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: lihua
 * @Date: 2024/4/15 10:44
 * @Version: v1.0.0
 * @Description:
 **/
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public Map<String,Object> userRegist(User user){
        User userOld = userMapper.getByStudentIdOrName(user.getStudentId(),user.getUsername());
        Map<String ,Object> retData = new HashMap<>();
        if(userOld != null){
            retData.put("code",500);
            retData.put("message","用户名或密码重复");
        }else {
            userMapper.insertUser(user);
            retData.put("code",200);
            retData.put("message","注册成功!");
        }
        return retData;
    }

    public List<User> getAllUser(){
        List<User> users = userMapper.getUser(new HashMap<>());
        return users;
    }
}
